package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.CopyrightAuction;
import com.sc.nft.entity.vo.CopyrightAuctionAdminPageVO;
import com.sc.nft.mapper.CopyrightAuctionMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.dao
 * @Project：sc_metago
 * @name：CopyrightAuctionDao
 * @Date：2024/9/12 17:39
 * @Filename：CopyrightAuctionDao
 */
@Slf4j
@Repository
public class CopyrightAuctionDao extends ServiceImpl<CopyrightAuctionMapper, CopyrightAuction> {
    public IPage<CopyrightAuctionAdminPageVO> collectionPage(String name, Page mp) {
        return baseMapper.collectionPage(mp,name);
    }

    public CopyrightAuction getByCollectionId(Long collectionId) {
        LambdaQueryWrapper<CopyrightAuction> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CopyrightAuction::getCollectionId, collectionId);
        queryWrapper.last("order by id desc limit 1");
        return this.getOne(queryWrapper);
    }

    public boolean updateStatus(Long id, Boolean status) {
        LambdaUpdateWrapper<CopyrightAuction> queryWrapper = new LambdaUpdateWrapper<>();
        queryWrapper.eq(CopyrightAuction::getId, id);
        queryWrapper.set(CopyrightAuction::getStatus,status);
        return this.update(queryWrapper);
    }

    public boolean updateStartPrice(Long id, Integer startPrice) {
        LambdaUpdateWrapper<CopyrightAuction> queryWrapper = new LambdaUpdateWrapper<>();
        queryWrapper.eq(CopyrightAuction::getId, id);
        queryWrapper.set(CopyrightAuction::getStartPrice,startPrice);
        return this.update(queryWrapper);
    }
}
